local liye = fk.CreateSkill {
  name = "th_liye",
}

liye:addAcquireEffect(function(self, player, is_start)
  if not is_start then
    local room = player.room
    local mark = {}
    room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
      local dat = e.data ---@type UseCardData
      if dat.from == player and dat.card then
        table.insertIfNeed(mark, dat.card.type)
      end
      return false
    end, Player.HistoryTurn)
    room:setPlayerMark(player, "th_liye-turn", mark)
  end
end)
liye:addEffect("viewas", {
  name = "th_liye",
  anim_type = "offensive",
  pattern = "analeptic",
  mute_card = false,
  handly_pile = true,
  prompt = function(self, player)
    local p = Fk:translate("#th_liye-use")
    local mark = player:getTableMark("th_liye-turn")
    local n = #mark
    if table.contains(mark, Card.TypeBasic) then
      n = n - 1
    end
    if player and player:usedSkillTimes(liye.name) == n then
      p = p .. Fk:translate("#th_liye-after")
    end
    return p
  end,
  card_num = 1,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("analeptic")
    card:addSubcards(cards)
    card.skillName = liye.name
    return card
  end,
  before_use = function(self, player, use)
    use.extraUse = true
  end,
  after_use = function(self, player, use)
    local room = player.room
    local x = #player:getTableMark("th_liye-turn")
    if player:usedSkillTimes(liye.name) == x then
      if x > 1 then
        player:drawCards(x - 1, liye.name)
      end
      room:invalidateSkill(player, liye.name, "-turn", liye.name)
      room:setPlayerMark(player, "@@th_liye", 1)
    end
  end,
  enabled_at_play = function(self, player)
    return not player:isNude()
  end,
  enabled_at_response = function(self, player, response)
    return not response and not player:isNude()
  end
})
liye:addEffect(fk.CardUsing, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player.phase < Player.NotActive
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local mark = {}
    mark = player:getTableMark("th_liye-turn")
    table.insertIfNeed(mark, data.card.type)
    room:setPlayerMark(player, "th_liye-turn", mark)
    if player:getMark("@@th_liye") ~= 0 then
      room:setPlayerMark(player, "@@th_liye", 0)
      data.disresponsiveList = player.room:getAlivePlayers(false)
    end
  end,
})

Fk:loadTranslationTable{
  ["th_liye"] = "力业",
  [":th_liye"] = "你可以将黑色牌当不计入次数的【酒】使用，你于回合内第X次以此法使用【酒】后，你摸X-1张牌并令本回合此技能失效，然后你使用的下一张牌不可响应（X为你本回合使用过的牌类型数）。",

  ["#th_liye-use"] = "力业：将黑色牌当不计入次数的【酒】使用",
  ["#th_liye-after"] = "，然后本回合此技能失效，你使用的下一张牌不可响应",

  ["@@th_liye"] = "力业",
}

return liye